package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Product;
import cn.wolfcode.trip.base.domain.ShopingCar;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.mapper.ProductMapper;
import cn.wolfcode.trip.base.query.ProductQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IProductService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements IProductService {
    @Autowired
    private ProductMapper productMapper;

    @Override
    public PageInfo query(ProductQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Product> list = productMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public Product selectProductById(Long id) {
        return productMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Product> getOrderProducts(Long[] arr) {
        return productMapper.getOrderProducts(arr);
    }

    @Override
    public void saveOrUpdate(Product product) {
        if (product.getId() == null) {
            productMapper.insert(product);
        }else{
            productMapper.updateByPrimaryKey(product);
        }
    }

    @Override
    public void deleteById(Long id) {
        productMapper.deleteByPrimaryKey(id);
    }


}
